package ca.mcgill.model.digraph.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ca.mcgill.model.functional.AsynchronousFSMsNetwork;
import ca.mcgill.model.functional.FiniteStateMachine;
import ca.mcgill.model.functional.Transition;
import ca.mcgill.model.functional.triggering.Event;

/**
 * This class implements some methods which can be usefull to be run before the
 * generation of the digraph.
 * 
 * @author EW228618
 * 
 */
public class PreprocessingUtils {

	Map<Event, List<Transition>> eventSrcTrans;

	public PreprocessingUtils(AsynchronousFSMsNetwork fsmNetwork) {
		this.eventSrcTrans = findEventsSrcTransitions(fsmNetwork);
	}

	public Map<Event, List<Transition>> findEventsSrcTransitions(
			AsynchronousFSMsNetwork fsmNetwork) {

		Map<Event, List<Transition>> eventSrcTrans = new HashMap<Event, List<Transition>>();

		for (FiniteStateMachine fsm : fsmNetwork.getFsms()) {

			for (Transition trans : fsm.getTransitions()) {

				List<Transition> res = null;

				if ((res = eventSrcTrans.get(trans.getOutE())) == null) {
					res = new ArrayList<Transition>();
				}

				res.add(trans);

				eventSrcTrans.put(trans.getOutE(), res);

			}

		}

		return eventSrcTrans;

	}

	public Map<Event, List<Transition>> getEventsSrcTransitions(){
		return this.eventSrcTrans;
	}
}
